﻿using furion.blog.Application.Contracts;
using furion.blog.Domain.IRepositories;
using furion.blog.Domain.MySQL;
using furion.blog.Domain.Query.Feedback;
using furion.blog.Domain.Shared;
using furion.blog.Domain.Shared.Dto.Feedback;
using furion.blog.Domain.Shared.Enum;
using furion.blog.Utils;
using Furion.DependencyInjection;
using Furion.FriendlyException;
using Mapster;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Application
{
    public class FeedbackService : IFeedbackService, ISingleton
    {

        private readonly IFeedbackRepository _feedbackRepository;

        public FeedbackService(IFeedbackRepository feedbackRepository) {
            this._feedbackRepository = feedbackRepository;
        }

        /// <summary>
        /// 新增反馈信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<bool> Add(FeedbackCreateDto dto)
        {
           Feedback model = dto.Adapt<Feedback>();
            model.FeedbackId = IdUtil.Id();
            model.IsDelete = YesOrNoEnum.No.ToString();
            return await this._feedbackRepository.Save(model);
        }


        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageVO> List(FeedbackListQuery query) {
            return await this._feedbackRepository.List(query);
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="feedbackId"></param>
        /// <returns></returns>
        public async Task<bool> Del(long feedbackId) {
            Feedback model = await this._feedbackRepository.FindById(feedbackId);
            if (model == null) {
                throw Oops.Oh("信息不存在");
            }
            model.IsDelete = YesOrNoEnum.Yes.ToString();
            return await this._feedbackRepository.Update(model);
        }

    }
}
